<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;

class Admin extends Authenticatable implements JWTSubject
{

    protected $fillable = ['account','username','password','status'];

    protected $hidden = ['password'];

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }


    public function getJWTCustomClaims()
    {
        return [
            'role' => 'admin'
        ];
    }

    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = bcrypt($value);
    }

    public function getStatusAttribute()
    {
        return boolval($this->attributes['status']);
    }

    public function roles()
    {
        return $this->belongsToMany(Role::class,'admin_role_pivot','admin_id','role_id');
    }

    /**
     * 状态启用
     */
    const STATUS_ENABLE = 1;

    /**
     * 状态禁用
     */
    const STATUS_DISABLE = 2;
}
